
#include "pr2000_support.h"
#if defined(__HOST_LINUX_SYSTEM__)
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#elif defined(__HOST_MICOM_SYSTEM__)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(STM32F10X_HD)
#include "stm32f10x.h"
#else
//#include "stm8s.h"
#endif

//#include "uart.h"
//#include "delay.h"
//#include "user_func.h"
#endif
#include "pr2000.h"
#include "pr2000_table.h"
#include "pr2000_func.h"
#include "pr2000_user_config.h"
#include "pr2000_ceqfunc.h"
#include "typedef.h"
#include "pr2000_drvcommon.h"
extern int PR2000_ProcessCameraMonitor1(const int i2cFd, const uint8_t slvAddr, enum _eBitIrq bitIrq, void*pArg);

int PR2000_ProcessCameraMonitor(
    const int i2cFd, const uint8_t slvAddr, enum _eBitIrq bitIrq, void*pArg)
{
    int result
        = -1;
    _drvHost*pHost = (_drvHost*)pArg;
    _stPR2000_Isr*pstIsr = (_stPR2000_Isr*)&pHost->
                           stPR2000_Isr;
    _stPR2000_Reg stReg;
    uint8_t u8RegData;
    int regInx = 0;
    enum
    _eCameraStandard cameraStandard;
    enum _eCameraResolution cameraResolution;
    enum
    _eVideoResolution videoResolution;
    int reJudge = 0;
    _stPR2000_VidStatusReg
    curStVidStatusReg;
#ifdef SUPPORT_CEQ
    _stPR2000_MeasureEqInfo stMeasureEqInfo;
#endif
    uint32_t tunnChromaPhase = 0;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(\
SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
    const _stPR2000_Table_ETC_EXTResolution*pTblETCEXTResolution = NULL;
#endif
    Dbg(
        "\x25\x78\x2d\x43\x61\x6d\x4d\x6f\x6e\x4e\x75\x6d\x4a\x6f\x62\x53\x74\x65\x70\x3a\x25\x64\x2c\x20\x69\x72\x71\x3a\x25\x64" "\n"
        , slvAddr COMMA pstIsr->stJobProc.numJobStep COMMA bitIrq);
#ifdef SUPPORT_PROC_SYSTEM
#ifdef SUPPORT_CEQ
    SET_STEP_BIT(pstIsr->stJobProc.numJobStep, pHost->stCEQInfo.stepBits);
#endif
#endif


    if(pstIsr->stJobProc.numJobStep < 50)
    {
        ErrorString(
            "\x49\x6e\x76\x61\x6c\x69\x64\x20\x6e\x75\x6d\x4a\x6f\x62\x53\x74\x65\x70" "\n")
        ;
        return(-1);
    }
    if(_TEST_BIT(JOB_START_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess) && !
       _TEST_BIT(JOB_DOING_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess))
    {
        Print(
            "\x25\x78\x2d\x61\x73\x73\x75\x6d\x65\x20\x74\x69\x6d\x65\x72\x30\x75\x70" "\n",
            slvAddr);
        bitIrq = IRQ_TIMER0UP;
    }
    if((bitIrq == IRQ_TIMER0UP) && (pstIsr->stJobProc.
                                    numJobStep == 50))
    {
        if(DEFAULT_AUTODETECT_ENABLE)
        {
            if(pstIsr->stJobProc.reJudgeStdResol)
            {
                PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
                if((curStVidStatusReg.
                    b.det_ifmt_res != pstIsr->stJobProc.stStartVidStatusReg.b.det_ifmt_res) || (
                       curStVidStatusReg.b.det_ifmt_ref != pstIsr->stJobProc.stStartVidStatusReg.b.
                       det_ifmt_ref) || (curStVidStatusReg.b.det_ifmt_std != pstIsr->stJobProc.
                                         stStartVidStatusReg.b.det_ifmt_std))
                {
                    Print(
                        "\x25\x78\x2d\x43\x68\x61\x6e\x67\x65\x3a\x20\x30\x78\x25\x30\x32\x78\x2d\x3e\x30\x78\x25\x30\x32\x78" "\n"
                        , slvAddr COMMA pstIsr->stJobProc.stStartVidStatusReg.reg[0]COMMA
                        curStVidStatusReg.reg[0]);
                    memset(&pstIsr->stJobProc, 0, sizeof(_stJobProc));
                    _SET_BIT(IRQ_NOVID, &pstIsr->stUserPoll.bitIrq);
                    _CLEAR_BIT(IRQ_NOVID, &pstIsr->
                               stUserPoll.bitIrqStatus);
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION) || defined(\
SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
                    if(curStVidStatusReg.b.det_ifmt_res == DET_HD960p)
                    {
                        pTblETCEXTResolution = (const
                                                _stPR2000_Table_ETC_EXTResolution*)stPR2000_Table_ETC_EXTResol;
#if defined(SUPPORT_EXTEND_HD_VIDEO_800P_RESOLUTION)
                        Print(
                            "\x25\x78\x2d\x57\x72\x69\x74\x65\x20\x70\x72\x65\x20\x73\x65\x74\x74\x69\x6e\x67\x20\x66\x6f\x72\x20\x38\x30\x30\x70\x28\x72\x65\x66\x3a\x25\x64\x29" "\n"
                            , slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
                        switch(curStVidStatusReg.b.
                               det_ifmt_ref)
                        {
                            case DET_25Hz:
                                videoResolution = video_1280x800p25;
                                break;
                            case
                                    DET_30Hz:
                                videoResolution = video_1280x800p30;
                                break;
                            case DET_50Hz:
                                videoResolution =
                                    video_1280x800p50;
                                break;
                            case DET_60Hz:
                                videoResolution = video_1280x800p60;
                                break;
                            default:
                                videoResolution = video_1280x800p25;
                                break;
                        }
                        regInx = 0;
                        stReg.reg =
                            pTblETCEXTResolution[regInx].stReg.reg;
                        while(stReg.reg != 0xffff)
                        {
                            u8RegData =
                                pTblETCEXTResolution[regInx].u8Data[videoResolution - video_1280x800p60];
                            Dbg(
                                "\x69\x6e\x78\x3a\x25\x64\x2c\x20\x70\x61\x67\x65\x3a\x25\x64\x2c\x20\x72\x65\x67\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x64\x61\x74\x61\x3a\x30\x78\x25\x30\x32\x78" "\n"
                                , regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
                            if((result =
                                    PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                            {
                                ErrorString(
                                    "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                                ;
                                return(result);
                            }
                            regInx++;
                            stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
                        }
#elif defined(SUPPORT_EXTEND_HD_VIDEO_960P_RESOLUTION)
                        Print(
                            "\x25\x78\x2d\x57\x72\x69\x74\x65\x20\x70\x72\x65\x20\x73\x65\x74\x74\x69\x6e\x67\x20\x66\x6f\x72\x20\x39\x36\x30\x70\x28\x72\x65\x66\x3a\x25\x64\x29" "\n"
                            , slvAddr COMMA curStVidStatusReg.b.det_ifmt_ref);
                        switch(curStVidStatusReg.b.
                               det_ifmt_ref)
                        {
                            case DET_25Hz:
                                videoResolution = video_1280x960p25;
                                break;
                            case
                                    DET_30Hz:
                                videoResolution = video_1280x960p30;
                                break;
                            case DET_50Hz:
                                videoResolution =
                                    video_1280x960p50;
                                break;
                            case DET_60Hz:
                                videoResolution = video_1280x960p60;
                                break;
                            default:
                                videoResolution = video_1280x960p25;
                                break;
                        }
                        regInx = 0;
                        stReg.reg =
                            pTblETCEXTResolution[regInx].stReg.reg;
                        while(stReg.reg != 0xffff)
                        {
                            u8RegData =
                                pTblETCEXTResolution[regInx].u8Data[videoResolution - video_1280x960p60];
                            Dbg(
                                "\x69\x6e\x78\x3a\x25\x64\x2c\x20\x70\x61\x67\x65\x3a\x25\x64\x2c\x20\x72\x65\x67\x3a\x30\x78\x25\x30\x32\x78\x2c\x20\x64\x61\x74\x61\x3a\x30\x78\x25\x30\x32\x78" "\n"
                                , regInx COMMA stReg.b.page COMMA stReg.b.addr COMMA u8RegData);
                            if((result =
                                    PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                            {
                                ErrorString(
                                    "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                                ;
                                return(result);
                            }
                            regInx++;
                            stReg.reg = pTblETCEXTResolution[regInx].stReg.reg;
                        }
#endif
                    }
#endif
                    memcpy(&pstIsr->stJobProc.stStartVidStatusReg, &curStVidStatusReg, sizeof(
                               _stPR2000_VidStatusReg));
                    memcpy(&pstIsr->stJobProc.stVidStatusReg, &
                           curStVidStatusReg, sizeof(_stPR2000_VidStatusReg));
                    pstIsr->stJobProc.cntJobTry = 0;
                    _SET_BIT(JOB_START_CAMERA_IN, &pstIsr->stJobProc.bitJobProcess);
                    pstIsr->stJobProc
                    .numJobStep = 1;
                    pstIsr->stJobProc.cntWait300MsecTime = 0;
                    result = pstIsr->stJobProc.
                             numJobStep;
                    return(result);
                }
            }
        }
        //DbgString(
        //  "\x44\x6f\x69\x6e\x67\x20\x6d\x6f\x6e\x69\x74\x6f\x72\x69\x6e\x67" "\n");
        _SET_BIT(JOB_DOING_CAMERA_MONITOR, &pstIsr->stJobProc.bitJobProcess);
        if(pstIsr->
           stJobProc.C_LOCK_CNT != 1)
        {
            pstIsr->stJobProc.cntWait300MsecTime = 0;
            pstIsr->
            stJobProc.numJobStep = 51;
            pstIsr->stJobProc.cntJobTry = 0;
            result = pstIsr->stJobProc.
                     numJobStep;

        }
        else
        {
            if(pstIsr->stJobProc.EQ_CNT == 1)
            {
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 80;
                pstIsr->stJobProc.cntJobTry = 0;
                result = pstIsr->
                         stJobProc.numJobStep;

            }
            else
            {
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 100;
                pstIsr->stJobProc.cntJobTry = 0;
                result = pstIsr->stJobProc.numJobStep;

            }
        }
    }
    if((bitIrq == IRQ_TIMER0UP) && (pstIsr->stJobProc.numJobStep == 51))
    {
        Print(
            "\x25\x78\x2d\x63\x68\x65\x63\x6b\x20\x63\x5f\x6c\x6f\x63\x6b\x5f\x63\x6e\x74\x20\x28\x43\x5f\x4c\x4f\x43\x4b\x5f\x43\x4e\x54\x20\x21\x3d\x20\x31\x29" "\n"
            , slvAddr);
        PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
        PR2000_GetStdResol(i2cFd, slvAddr, &curStVidStatusReg, &cameraStandard, &
                           cameraResolution, &videoResolution, &reJudge);
        Dbg(
            "\x3d\x3d\x25\x78\x2f\x25\x78\x2f\x25\x78" "\n", curStVidStatusReg.reg[0]COMMA
            curStVidStatusReg.reg[1]COMMA curStVidStatusReg.reg[2]);
        if(((cameraStandard == HDA
            )) && ((cameraResolution == camera_1280x720p60) || (cameraResolution ==
                    camera_1280x720p50) || (cameraResolution == camera_1280x720p30) || (cameraResolution ==
                            camera_1280x720p25)))
        {
            if((curStVidStatusReg.b.det_chroma) && (curStVidStatusReg.b.
                                                    lock_chroma))
            {
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 65;
                pstIsr->stJobProc.cntJobTry
                    = 0;
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
            else if((
                        curStVidStatusReg.b.det_chroma) && (!curStVidStatusReg.b.lock_chroma))
            {
                pstIsr->
                stJobProc.cntChromaLockTunn = 0;
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->
                stJobProc.numJobStep = 60;
                pstIsr->stJobProc.cntJobTry = 0;
                bitIrq = IRQ_TIMER1UP;
                result
                    = pstIsr->stJobProc.numJobStep;

            }
            else
            {
                if((videoResolution == video_1280x720p30) || (videoResolution == video_1280x720p25))
                {
                    PR2000_SetTblBrief(i2cFd, slvAddr, HDA, videoResolution, 2, &pstIsr->stJobProc);
                }
                pstIsr->stJobProc.cntChromaLockTunn = 0;
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 70;
                pstIsr->stJobProc.cntJobTry = 0;
                bitIrq =
                    IRQ_TIMER1UP;
                result = pstIsr->stJobProc.numJobStep;

            }
        }
        else
        {
            if((curStVidStatusReg.b.det_chroma) && (curStVidStatusReg.b.lock_chroma))
            {
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->
                stJobProc.numJobStep = 55;
                pstIsr->stJobProc.cntJobTry = 0;
                result = pstIsr->stJobProc.
                         numJobStep;
                return(result);
            }
            else if((curStVidStatusReg.b.det_chroma) && (!
                    curStVidStatusReg.b.lock_chroma))
            {
                pstIsr->stJobProc.cntChromaLockTunn = 0;
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 52;
                pstIsr->stJobProc
                .cntJobTry = 0;
                bitIrq = IRQ_TIMER1UP;
                result = pstIsr->stJobProc.numJobStep;

            }
            else
            {
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 50;
                pstIsr->stJobProc.cntJobTry = 0;
                result = pstIsr->stJobProc.numJobStep;
                return(result)
                      ;
            }
        }
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.numJobStep == 52))
    {
        Print(
            "\x25\x78\x2d\x50\x56\x49\x2f\x54\x56\x49\x20\x43\x5f\x64\x65\x74\x20\x26\x20\x21\x43\x5f\x6c\x6f\x63\x6b\x20\x63\x68\x65\x63\x6b\x2e\x20\x74\x75\x6e\x6e\x20\x63\x68\x72\x6f\x6d\x61\x20\x70\x68\x61\x73\x65\x2e" "\n"
            , slvAddr);
        Print(
            "\x25\x78\x2d\x64\x65\x66\x43\x68\x72\x6f\x6d\x61\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78\x2c\x20\x63\x6e\x74\x54\x75\x6e\x6e\x3a\x25\x78" "\n"
            , slvAddr COMMA pstIsr->stJobProc.defChromaPhase COMMA pstIsr->stJobProc.
            cntChromaLockTunn);
        PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
        PR2000_GetStdResol(i2cFd, slvAddr, &curStVidStatusReg, &cameraStandard, &
                           cameraResolution, &videoResolution, &reJudge);
        if((!curStVidStatusReg.b.det_chroma)
           || (pstIsr->stJobProc.cntChromaLockTunn >= MAX_CNT_TUNN_CHROMALOCK))
        {
            Error(
                "\x43\x61\x6e\x27\x74\x20\x44\x65\x74\x20\x63\x68\x72\x6f\x6d\x61\x28\x25\x64\x29\x20\x6f\x72\x20\x4f\x76\x65\x72\x20\x63\x68\x65\x63\x6b\x20\x74\x69\x6d\x65\x28\x25\x64\x29\x20\x63\x68\x72\x6f\x6d\x61\x20\x6c\x6f\x63\x6b\x2e" "\n"
                , curStVidStatusReg.b.det_chroma COMMA pstIsr->stJobProc.cntChromaLockTunn);
            tunnChromaPhase = pstIsr->stJobProc.defChromaPhase;
            stReg.reg = 0x0146;
            u8RegData = ((
                             tunnChromaPhase >> 16) & 0x1f) | 0x00;
            if((result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) <
               0)
            {
                ErrorString(
                    "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                ;
                return(result);
            }
            stReg.reg = 0x0147;
            u8RegData = (tunnChromaPhase >> 8) & 0xff;
            if((result
                = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
            {
                ErrorString(
                    "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                ;
                return(result);
            }
            stReg.reg = 0x0148;
            u8RegData = (tunnChromaPhase) & 0xff;
            if((result =
                    PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
            {
                ErrorString(
                    "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                ;
                return(result);
            }
            Print(
                "\x25\x78\x2d\x54\x75\x6e\x6e\x20\x43\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78" "\n"
                , slvAddr COMMA tunnChromaPhase);
            {
                stReg.reg = 0x0154;
                u8RegData = 0x0e;
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0154;
                u8RegData = 0x0f;
                if((result = PR2000_PageWrite(
                                 i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
            }
            pstIsr->stJobProc.cntChromaLockTunn = 0;
            pstIsr->stJobProc.
            cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 50;
            pstIsr->stJobProc.cntJobTry
                = 0;
            result = pstIsr->stJobProc.numJobStep;
            return(result);
        }
        else if(pstIsr->stJobProc
                .cntChromaLockTunn < MAX_CNT_TUNN_CHROMALOCK)
        {
            if((curStVidStatusReg.b.det_chroma)
               && (curStVidStatusReg.b.lock_chroma))
            {
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                Print(
                    "\x25\x78\x2d\x66\x69\x6e\x64\x20\x6c\x6f\x63\x6b\x20\x63\x68\x72\x6f\x6d\x61" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntChromaLockTunn = 0;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 55;
                pstIsr->stJobProc.cntJobTry
                    = 0;
                Dbg(
                    "\x53\x65\x74\x20\x75\x73\x65\x72\x20\x66\x6c\x61\x67\x28\x25\x64\x2c\x25\x64\x2c\x25\x64\x29" "\n"
                    , cameraStandard COMMA cameraResolution COMMA videoResolution);
                if((pHost->
                    stPrRxMode.standard != cameraStandard) || (pHost->stPrRxMode.cameraResolution !=
                            cameraResolution) || (pHost->stPrRxMode.vidOutResolution != videoResolution))
                {
                    pHost
                    ->stPrRxMode.standard = cameraStandard;
                    pHost->stPrRxMode.cameraResolution =
                        cameraResolution;
                    pHost->stPrRxMode.vidOutResolution = videoResolution;
                    _SET_BIT(
                        IRQ_SET_RXMODE, &pstIsr->stUserPoll.bitIrq);
                    _SET_BIT(IRQ_SET_RXMODE, &pstIsr->
                             stUserPoll.bitIrqStatus);
                }
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
            else if((curStVidStatusReg.b.det_chroma) && (!curStVidStatusReg.b.lock_chroma))
            {
                tunnChromaPhase = (pstIsr->stJobProc.cntChromaLockTunn >> 1) + 1;
                tunnChromaPhase *= 40;
                if(pstIsr->stJobProc.cntChromaLockTunn & 1)
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase - tunnChromaPhase;
                }
                else
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase + tunnChromaPhase;
                }
                stReg.reg =
                    0x0146;
                u8RegData = ((tunnChromaPhase >> 16) & 0x1f) | 0x20;
                if((result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) <
                   0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0147;
                u8RegData = (tunnChromaPhase >> 8) & 0xff;
                if((result
                    = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0148;
                u8RegData = (tunnChromaPhase) & 0xff;
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                Print(
                    "\x25\x78\x2d\x54\x75\x6e\x6e\x20\x43\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78" "\n"
                    , slvAddr COMMA tunnChromaPhase);
                {
                    stReg.reg = 0x0154;
                    u8RegData = 0x0e;
                    if((result =
                            PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                    stReg.reg = 0x0154;
                    u8RegData = 0x0f;
                    if((result = PR2000_PageWrite(
                                     i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                }
                pstIsr->stJobProc.cntChromaLockTunn++;
                pstIsr->stJobProc.
                cntWait300MsecTime = 1;
                pstIsr->stJobProc.numJobStep = 52;
                result = pstIsr->stJobProc.
                         numJobStep;
                return(result);
            }
        }
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.
                                    numJobStep == 55))
    {
#ifdef SUPPORT_CEQ
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x35\x32\x29" "\n"
            , slvAddr);
        PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.
                                stDetGainStatus);
        PR2000_GetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.
                         stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                         stMeasureEqInfo);
        Dbg(
            "\x25\x78\x2d\x64\x63\x47\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78" "\n", pstIsr->
            stJobProc.stDetGainStatus.dcGain);
        if(pstIsr->stJobProc.stDetGainStatus.dcGain ==
           0xffff)
        {
            pstIsr->stJobProc.stTunnFactor.stepDir = -1;
            if(PR2000_GetTunnEQGain(i2cFd,
                                    slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &
                                    pstIsr->stJobProc.stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3d\x20\x30\x78\x46\x46\x46\x46\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x73\x74\x65\x70\x2e" "\n"
                    , slvAddr);
                PR2000_SetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                                 pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.stMeasureEqInfo);
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 55;
                if(pstIsr->
                   stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc.
                    cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 56;
                    pstIsr->stJobProc.cntJobTry
                        = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 56;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else if(pstIsr->stJobProc.stDetGainStatus.dcGain < 0x1300)
        {
            pstIsr->stJobProc.
            stTunnFactor.stepDir = -1;
            if(PR2000_SetTunnVADCGain(i2cFd, slvAddr, &pstIsr->
                                      stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                                      stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3c\x20\x30\x78\x31\x33\x30\x30\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x76\x61\x64\x63\x67\x61\x69\x6e\x2e" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 55
                                               ;
                if(pstIsr->stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc
                    .cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 56;
                    pstIsr->stJobProc.
                    cntJobTry = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 56;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else
        {
            Dbg(
                "\x25\x78\x2d\x45\x6e\x64\x20\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x35\x32\x29" "\n"
                , slvAddr);
            pstIsr->stJobProc.cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 56
                                           ;
            pstIsr->stJobProc.cntJobTry = 0;

        }
#else
        pstIsr->stJobProc.EQ_CNT = 2;
        pstIsr->stJobProc.cntWait300MsecTime = 0;
        pstIsr->
        stJobProc.numJobStep = 50;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->stJobProc.
                 numJobStep;
        return(result);
#endif
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.numJobStep == 56))
    {
#ifdef SUPPORT_CEQ
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x35\x32\x29" "\n"
            , slvAddr);
        PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.
                                stDetGainStatus);
        PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.
                           stVidStatusReg, &cameraStandard, &cameraResolution, &videoResolution, &reJudge);
        Dbg(
            "\x25\x78\x2d\x61\x74\x74\x65\x6e\x32\x3a\x30\x78\x25\x30\x34\x78\x2c\x20\x61\x63\x47\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78" "\n"
            , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.atten2 COMMA pstIsr->stJobProc.
            stDetGainStatus.acGain);
        if((pstIsr->stJobProc.stDetGainStatus.atten2 < 0x0500) || (
               pstIsr->stJobProc.stDetGainStatus.acGain < 0x0700))
        {
            pstIsr->stJobProc.stTunnFactor
            .stepDir = -1;
            if(PR2000_SetTunnEQBand(i2cFd, slvAddr, &pstIsr->stJobProc.
                                    stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                                    stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x61\x74\x74\x65\x6e\x32\x20\x3c\x20\x30\x78\x30\x35\x30\x30\x20\x6f\x72\x20\x61\x63\x47\x61\x69\x6e\x20\x3c\x20\x30\x78\x30\x37\x30\x30\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x62\x61\x6e\x64\x2e" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 56
                                               ;
                if(pstIsr->stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc
                    .EQ_CNT = 2;
                    pstIsr->stJobProc.C_LOCK_CNT = 1;
                    pstIsr->stJobProc.cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 50;
                    pstIsr->stJobProc.cntJobTry = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.EQ_CNT = 2;
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 50;
                pstIsr->stJobProc.cntJobTry
                    = 0;

            }
        }
        else
        {
            uint16_t tmpAtten2 = 0;
            if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 1200)
                tmpAtten2 = 0x1d00;
            else if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 1000)
                tmpAtten2 = 0x1800;
            else if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 800)
                tmpAtten2 = 0x1600;
            else if((pstIsr->stJobProc.stMeasureEqInfo.distComp > 600) || (
                        cameraStandard == SD))tmpAtten2 = 0x1400;
            else tmpAtten2 = 0x1100;
            if(pstIsr->stJobProc.
               stDetGainStatus.atten2 > tmpAtten2)
            {
                pstIsr->stJobProc.stTunnFactor.stepDir = 1;
                if(
                    PR2000_SetTunnEQBand(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->
                                         stJobProc.stDetGainStatus, &pstIsr->stJobProc.stTunnFactor, &pstIsr->stJobProc.
                                         stMeasureEqInfo) > 0)
                {
                    Print(
                        "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                        , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                        stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                        COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                        stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                        pstIsr->stJobProc.stDetGainStatus.atten2);
                    Print(
                        "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x28\x64\x69\x73\x74\x43\x6f\x6d\x70\x3a\x25\x64\x2c\x25\x73\x29\x20\x26\x26\x20\x28\x61\x74\x74\x65\x6e\x32\x20\x3e\x20\x30\x78\x25\x30\x34\x78\x29\x2c\x20\x69\x6e\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x62\x61\x6e\x64\x2e" "\n"
                        , slvAddr COMMA pstIsr->stJobProc.stMeasureEqInfo.distComp COMMA(cameraStandard ==
                                SD) ? "\x53\x44" : "\x48\x44" COMMA tmpAtten2);
                    pstIsr->stJobProc.cntWait300MsecTime =
                        0;
                    pstIsr->stJobProc.numJobStep = 56;
                    if(pstIsr->stJobProc.cntJobTry++ >
                       MAX_PR2000_CEQ_COMP_TBL_NUM)
                    {
                        pstIsr->stJobProc.EQ_CNT = 2;
                        pstIsr->stJobProc.
                        C_LOCK_CNT = 1;
                        pstIsr->stJobProc.cntWait300MsecTime = 0;
                        pstIsr->stJobProc.numJobStep
                            = 50;
                        pstIsr->stJobProc.cntJobTry = 0;

                    }
                    else
                    {
                        result = pstIsr->stJobProc.numJobStep;
                        return(result);
                    }
                }
                else
                {
                    pstIsr->
                    stJobProc.EQ_CNT = 2;
                    pstIsr->stJobProc.C_LOCK_CNT = 1;
                    pstIsr->stJobProc.
                    cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 50;
                    pstIsr->stJobProc.cntJobTry
                        = 0;

                }
            }
            else
            {
                Dbg(
                    "\x25\x78\x2d\x45\x6e\x64\x20\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x35\x32\x29" "\n"
                    , slvAddr);
                pstIsr->stJobProc.EQ_CNT = 2;
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 50;
                pstIsr->stJobProc
                .cntJobTry = 0;
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
        }
#else
        pstIsr->stJobProc.EQ_CNT = 2;
        pstIsr->stJobProc.cntWait300MsecTime = 0;
        pstIsr->
        stJobProc.numJobStep = 50;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->stJobProc.
                 numJobStep;
        return(result);
#endif
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.numJobStep == 60))
    {
        Print(
            "\x25\x78\x2d\x43\x56\x49\x20\x43\x5f\x64\x65\x74\x20\x26\x20\x21\x43\x5f\x6c\x6f\x63\x6b\x20\x63\x68\x65\x63\x6b\x2e\x20\x74\x75\x6e\x6e\x20\x63\x68\x72\x6f\x6d\x61\x20\x70\x68\x61\x73\x65\x2e" "\n"
            , slvAddr);
        Print(
            "\x25\x78\x2d\x64\x65\x66\x43\x68\x72\x6f\x6d\x61\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78\x2c\x20\x63\x6e\x74\x54\x75\x6e\x6e\x3a\x25\x78" "\n"
            , slvAddr COMMA pstIsr->stJobProc.defChromaPhase COMMA pstIsr->stJobProc.
            cntChromaLockTunn);
        PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
        if(
            (!curStVidStatusReg.b.det_chroma) || (pstIsr->stJobProc.cntChromaLockTunn >=
                    MAX_CNT_TUNN_CHROMALOCK))
        {
            Error(
                "\x43\x61\x6e\x27\x74\x20\x44\x65\x74\x20\x63\x68\x72\x6f\x6d\x61\x28\x25\x64\x29\x20\x6f\x72\x20\x4f\x76\x65\x72\x20\x63\x68\x65\x63\x6b\x20\x74\x69\x6d\x65\x28\x25\x64\x29\x20\x63\x68\x72\x6f\x6d\x61\x20\x6c\x6f\x63\x6b\x2e" "\n"
                , curStVidStatusReg.b.det_chroma COMMA pstIsr->stJobProc.cntChromaLockTunn);
            Print
            (
                "\x25\x78\x2d\x46\x6f\x72\x63\x65\x6c\x79\x20\x52\x65\x74\x75\x72\x6e\x20\x73\x65\x74\x20\x61\x62\x6e\x6f\x72\x6d\x61\x6c\x20\x53\x54\x44\x28\x43\x56\x49\x29" "\n"
                , slvAddr);
            pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_CVI;
            PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                               cameraStandard, &cameraResolution, &videoResolution, &reJudge);
            Print(
                "\x25\x78\x2d\x66\x6f\x72\x6d\x61\x74\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
                , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
                cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
                videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
            Print(
                "\x25\x78\x2d\x49\x6e\x69\x74\x20\x76\x64\x65\x63\x2c\x20\x43\x50\x68\x61\x73\x65\x52\x65\x66\x2e\x2e\x2e" "\n"
                , slvAddr);
            pstIsr->stJobProc.defChromaPhase = 0;
            if((result = PR2000_SetTblBrief(i2cFd, slvAddr, cameraStandard, videoResolution, 1, &
                                            pstIsr->stJobProc)) < 0)
            {
                ErrorString(
                    "\x43\x61\x6e\x27\x74\x20\x73\x65\x74\x20\x74\x61\x62\x6c\x65\x20\x62\x72\x69\x65\x66" "\n"
                );
                return(result);
            }
            pstIsr->stJobProc.cntChromaLockTunn = 0;
            pstIsr->stJobProc.
            cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 50;
            pstIsr->stJobProc.cntJobTry = 0;
            result = pstIsr->
                     stJobProc.numJobStep;
            return(result);
        }
        else if(pstIsr->stJobProc.cntChromaLockTunn
                < MAX_CNT_TUNN_CHROMALOCK)
        {
            if((curStVidStatusReg.b.det_chroma) && (
                   curStVidStatusReg.b.lock_chroma))
            {
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                Print(
                    "\x25\x78\x2d\x66\x69\x6e\x64\x20\x6c\x6f\x63\x6b\x20\x63\x68\x72\x6f\x6d\x61" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntChromaLockTunn = 0;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 65;
                pstIsr->stJobProc.cntJobTry
                    = 0;
                pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_CVI;
                PR2000_GetStdResol(
                    i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &cameraStandard, &
                    cameraResolution, &videoResolution, &reJudge);
                Dbg(
                    "\x53\x65\x74\x20\x75\x73\x65\x72\x20\x66\x6c\x61\x67\x28\x25\x64\x2c\x25\x64\x2c\x25\x64\x29" "\n"
                    , cameraStandard COMMA cameraResolution COMMA videoResolution);
                if((pHost->
                    stPrRxMode.standard != cameraStandard) || (pHost->stPrRxMode.cameraResolution !=
                            cameraResolution) || (pHost->stPrRxMode.vidOutResolution != videoResolution))
                {
                    pHost
                    ->stPrRxMode.standard = cameraStandard;
                    pHost->stPrRxMode.cameraResolution =
                        cameraResolution;
                    pHost->stPrRxMode.vidOutResolution = videoResolution;
                    _SET_BIT(
                        IRQ_SET_RXMODE, &pstIsr->stUserPoll.bitIrq);
                    _SET_BIT(IRQ_SET_RXMODE, &pstIsr->
                             stUserPoll.bitIrqStatus);
                }
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
            else if((curStVidStatusReg.b.det_chroma) && (!curStVidStatusReg.b.lock_chroma))
            {
                tunnChromaPhase = (pstIsr->stJobProc.cntChromaLockTunn >> 1) + 1;
                tunnChromaPhase *= 40;
                if(pstIsr->stJobProc.cntChromaLockTunn & 1)
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase - tunnChromaPhase;
                }
                else
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase + tunnChromaPhase;
                }
                stReg.reg =
                    0x0146;
                u8RegData = ((tunnChromaPhase >> 16) & 0x1f) | 0x20;
                if((result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) <
                   0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0147;
                u8RegData = (tunnChromaPhase >> 8) & 0xff;
                if((result
                    = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0148;
                u8RegData = (tunnChromaPhase) & 0xff;
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                Print(
                    "\x25\x78\x2d\x54\x75\x6e\x6e\x20\x43\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78" "\n"
                    , slvAddr COMMA tunnChromaPhase);
                {
                    stReg.reg = 0x0154;
                    u8RegData = 0x0e;
                    if((result =
                            PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                    stReg.reg = 0x0154;
                    u8RegData = 0x0f;
                    if((result = PR2000_PageWrite(
                                     i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                }
                pstIsr->stJobProc.cntChromaLockTunn++;
                pstIsr->stJobProc.
                cntWait300MsecTime = 1;
                pstIsr->stJobProc.numJobStep = 60;
                result = pstIsr->stJobProc.
                         numJobStep;
                return(result);
            }
        }
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.
                                    numJobStep == 65))
    {
        PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                           cameraStandard, &cameraResolution, &videoResolution, &reJudge);
        Print(
            "\x25\x78\x2d\x66\x6f\x72\x6d\x61\x74\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
        if((videoResolution == video_1280x720p30) || (videoResolution == video_1280x720p25))
        {
            PR2000_SetTblBrief(i2cFd, slvAddr, cameraStandard, videoResolution, 2, &pstIsr->
                               stJobProc);
        }
#ifdef SUPPORT_CEQ
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x36\x30\x29" "\n"
            , slvAddr);
        PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.
                                stDetGainStatus);
        PR2000_GetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.
                         stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                         stMeasureEqInfo);
        Dbg(
            "\x25\x78\x2d\x64\x63\x47\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78" "\n", pstIsr->
            stJobProc.stDetGainStatus.dcGain);
        if(pstIsr->stJobProc.stDetGainStatus.dcGain ==
           0xffff)
        {
            pstIsr->stJobProc.stTunnFactor.stepDir = -1;
            if(PR2000_GetTunnEQGain(i2cFd,
                                    slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &
                                    pstIsr->stJobProc.stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3d\x20\x30\x78\x46\x46\x46\x46\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x73\x74\x65\x70\x2e" "\n"
                    , slvAddr);
                PR2000_SetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                                 pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.stMeasureEqInfo);
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 65;
                if(pstIsr->
                   stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc.
                    cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 66;
                    pstIsr->stJobProc.cntJobTry
                        = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 66;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else if(pstIsr->stJobProc.stDetGainStatus.dcGain < 0x1300)
        {
            pstIsr->stJobProc.
            stTunnFactor.stepDir = -1;
            if(PR2000_SetTunnVADCGain(i2cFd, slvAddr, &pstIsr->
                                      stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                                      stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3c\x20\x30\x78\x31\x33\x30\x30\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x76\x61\x64\x63\x67\x61\x69\x6e\x2e" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 65
                                               ;
                if(pstIsr->stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc
                    .cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 66;
                    pstIsr->stJobProc.
                    cntJobTry = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 66;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else
        {
            Dbg(
                "\x25\x78\x2d\x45\x6e\x64\x20\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x36\x30\x29" "\n"
                , slvAddr);
            pstIsr->stJobProc.cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 66
                                           ;
            pstIsr->stJobProc.cntJobTry = 0;

        }
#else
        pstIsr->stJobProc.EQ_CNT = 2;
        pstIsr->stJobProc.cntWait300MsecTime = 0;
        pstIsr->
        stJobProc.numJobStep = 50;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->stJobProc.
                 numJobStep;
        return(result);
#endif
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.numJobStep == 66))
    {
#ifdef SUPPORT_CEQ
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x36\x30\x29" "\n"
            , slvAddr);
        PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.
                                stDetGainStatus);
        PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.
                           stVidStatusReg, &cameraStandard, &cameraResolution, &videoResolution, &reJudge);
        Dbg(
            "\x25\x78\x2d\x61\x74\x74\x65\x6e\x32\x3a\x30\x78\x25\x30\x34\x78\x2c\x20\x61\x63\x47\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78" "\n"
            , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.atten2 COMMA pstIsr->stJobProc.
            stDetGainStatus.acGain);
        if((pstIsr->stJobProc.stDetGainStatus.atten2 < 0x0500) || (
               pstIsr->stJobProc.stDetGainStatus.acGain < 0x0700))
        {
            pstIsr->stJobProc.stTunnFactor
            .stepDir = -1;
            if(PR2000_SetTunnEQBand(i2cFd, slvAddr, &pstIsr->stJobProc.
                                    stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                                    stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x61\x74\x74\x65\x6e\x32\x20\x3c\x20\x30\x78\x30\x35\x30\x30\x20\x6f\x72\x20\x61\x63\x47\x61\x69\x6e\x20\x3c\x20\x30\x78\x30\x37\x30\x30\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x62\x61\x6e\x64\x2e" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 66
                                               ;
                if(pstIsr->stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc
                    .EQ_CNT = 2;
                    pstIsr->stJobProc.C_LOCK_CNT = 1;
                    pstIsr->stJobProc.cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 50;
                    pstIsr->stJobProc.cntJobTry = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.EQ_CNT = 2;
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 50;
                pstIsr->stJobProc.cntJobTry
                    = 0;

            }
        }
        else
        {
            uint16_t tmpAtten2 = 0;
            if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 1200)
                tmpAtten2 = 0x1d00;
            else if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 1000)
                tmpAtten2 = 0x1800;
            else if(pstIsr->stJobProc.stMeasureEqInfo.distComp > 800)
                tmpAtten2 = 0x1600;
            else if((pstIsr->stJobProc.stMeasureEqInfo.distComp > 600) || (
                        cameraStandard == SD))tmpAtten2 = 0x1400;
            else tmpAtten2 = 0x1100;
            if(pstIsr->stJobProc.
               stDetGainStatus.atten2 > tmpAtten2)
            {
                pstIsr->stJobProc.stTunnFactor.stepDir = 1;
                if(
                    PR2000_SetTunnEQBand(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->
                                         stJobProc.stDetGainStatus, &pstIsr->stJobProc.stTunnFactor, &pstIsr->stJobProc.
                                         stMeasureEqInfo) > 0)
                {
                    Print(
                        "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                        , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                        stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                        COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                        stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                        pstIsr->stJobProc.stDetGainStatus.atten2);
                    Print(
                        "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x28\x64\x69\x73\x74\x43\x6f\x6d\x70\x3a\x25\x64\x2c\x25\x73\x29\x20\x26\x26\x20\x28\x61\x74\x74\x65\x6e\x32\x20\x3e\x20\x30\x78\x25\x30\x34\x78\x29\x2c\x20\x69\x6e\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x62\x61\x6e\x64\x2e" "\n"
                        , slvAddr COMMA pstIsr->stJobProc.stMeasureEqInfo.distComp COMMA(cameraStandard ==
                                SD) ? "\x53\x44" : "\x48\x44" COMMA tmpAtten2);
                    pstIsr->stJobProc.cntWait300MsecTime =
                        0;
                    pstIsr->stJobProc.numJobStep = 66;
                    if(pstIsr->stJobProc.cntJobTry++ >
                       MAX_PR2000_CEQ_COMP_TBL_NUM)
                    {
                        pstIsr->stJobProc.EQ_CNT = 2;
                        pstIsr->stJobProc.
                        C_LOCK_CNT = 1;
                        pstIsr->stJobProc.cntWait300MsecTime = 0;
                        pstIsr->stJobProc.numJobStep
                            = 50;
                        pstIsr->stJobProc.cntJobTry = 0;

                    }
                    else
                    {
                        result = pstIsr->stJobProc.numJobStep;
                        return(result);
                    }
                }
                else
                {
                    pstIsr->
                    stJobProc.EQ_CNT = 2;
                    pstIsr->stJobProc.C_LOCK_CNT = 1;
                    pstIsr->stJobProc.
                    cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 50;
                    pstIsr->stJobProc.cntJobTry
                        = 0;

                }
            }
            else
            {
                Dbg(
                    "\x25\x78\x2d\x45\x6e\x64\x20\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x32\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x36\x30\x29" "\n"
                    , slvAddr);
                pstIsr->stJobProc.EQ_CNT = 2;
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 50;
                pstIsr->stJobProc
                .cntJobTry = 0;
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
        }
#else
        pstIsr->stJobProc.EQ_CNT = 2;
        pstIsr->stJobProc.cntWait300MsecTime = 0;
        pstIsr->
        stJobProc.numJobStep = 50;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->stJobProc.
                 numJobStep;
        return(result);
#endif
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.numJobStep == 70))
    {
        Print(
            "\x25\x78\x2d\x53\x65\x74\x20\x48\x44\x41\x20\x66\x6f\x72\x6d\x61\x74" "\n",
            slvAddr);
        Print(
            "\x25\x78\x2d\x46\x6f\x72\x63\x65\x6c\x79\x20\x53\x65\x74\x20\x74\x65\x6d\x70\x6f\x72\x61\x79\x20\x61\x62\x6e\x6f\x72\x6d\x61\x6c\x20\x53\x54\x44\x28\x48\x44\x41\x29" "\n"
            , slvAddr);
        pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_HDA;
        PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                           cameraStandard, &cameraResolution, &videoResolution, &reJudge);
        Print(
            "\x25\x78\x2d\x66\x6f\x72\x6d\x61\x74\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
            , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
            cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
            videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
        Print(
            "\x25\x78\x2d\x53\x65\x74\x20\x76\x64\x65\x63\x2c\x20\x43\x50\x68\x61\x73\x65\x52\x65\x66\x2e\x2e\x2e" "\n"
            , slvAddr);
        pstIsr->stJobProc.defChromaPhase = 0;
        if((result = PR2000_SetTblBrief(i2cFd, slvAddr, cameraStandard, videoResolution, 1, &
                                        pstIsr->stJobProc)) < 0)
        {
            ErrorString(
                "\x43\x61\x6e\x27\x74\x20\x73\x65\x74\x20\x74\x61\x62\x6c\x65\x20\x62\x72\x69\x65\x66" "\n"
            );
            return(result);
        }
        pstIsr->stJobProc.cntChromaLockTunn = 0;
        pstIsr->stJobProc.
        cntWait300MsecTime = 1;
        pstIsr->stJobProc.numJobStep = 71;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->
                 stJobProc.numJobStep;
        return(result);
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->
                                    stJobProc.numJobStep == 71))
    {
        Print(
            "\x25\x78\x2d\x48\x44\x41\x20\x43\x5f\x64\x65\x74\x20\x26\x20\x21\x43\x5f\x6c\x6f\x63\x6b\x20\x63\x68\x65\x63\x6b\x2e\x20\x74\x75\x6e\x6e\x20\x63\x68\x72\x6f\x6d\x61\x20\x70\x68\x61\x73\x65\x2e" "\n"
            , slvAddr);
        Print(
            "\x25\x78\x2d\x64\x65\x66\x43\x68\x72\x6f\x6d\x61\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78\x2c\x20\x63\x6e\x74\x54\x75\x6e\x6e\x3a\x25\x78" "\n"
            , slvAddr COMMA pstIsr->stJobProc.defChromaPhase COMMA pstIsr->stJobProc.
            cntChromaLockTunn);
        PR2000_ReadVidStatusReg(i2cFd, slvAddr, &curStVidStatusReg);
        Dbg
        ("\x2d\x2d\x25\x78\x2f\x25\x78\x2f\x25\x78" "\n", curStVidStatusReg.reg[0]COMMA
         curStVidStatusReg.reg[1]COMMA curStVidStatusReg.reg[2]);
        if((!curStVidStatusReg.b
            .det_chroma) || (pstIsr->stJobProc.cntChromaLockTunn >= MAX_CNT_TUNN_CHROMALOCK))
        {
            Dbg(
                "\x43\x61\x6e\x27\x74\x20\x44\x65\x74\x20\x63\x68\x72\x6f\x6d\x61\x28\x25\x64\x29\x20\x6f\x72\x20\x4f\x76\x65\x72\x20\x63\x68\x65\x63\x6b\x20\x74\x69\x6d\x65\x28\x25\x64\x29\x20\x63\x68\x72\x6f\x6d\x61\x20\x6c\x6f\x63\x6b\x2e" "\n"
                , curStVidStatusReg.b.det_chroma COMMA pstIsr->stJobProc.cntChromaLockTunn);
            Print
            (
                "\x25\x78\x2d\x46\x6f\x72\x63\x65\x6c\x79\x20\x52\x65\x74\x75\x72\x6e\x20\x73\x65\x74\x20\x61\x62\x6e\x6f\x72\x6d\x61\x6c\x20\x53\x54\x44\x28\x43\x56\x49\x29" "\n"
                , slvAddr);
            pstIsr->stJobProc.stVidStatusReg.b.det_ifmt_std = DET_CVI;
            PR2000_GetStdResol(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                               cameraStandard, &cameraResolution, &videoResolution, &reJudge);
            Print(
                "\x25\x78\x2d\x66\x6f\x72\x6d\x61\x74\x5b\x43\x61\x6d\x65\x72\x61\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x63\x61\x6d\x65\x72\x61\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x2c\x20\x76\x69\x64\x65\x6f\x52\x65\x73\x6f\x6c\x75\x74\x69\x6f\x6e\x3a\x25\x64\x28\x25\x73\x29\x20\x72\x65\x4a\x75\x64\x67\x65\x3a\x25\x64\x5d" "\n"
                , slvAddr COMMA cameraStandard COMMA _strCameraStandard[cameraStandard]COMMA
                cameraResolution COMMA _strCameraResolution[cameraResolution]COMMA
                videoResolution COMMA _strVideoResolution[videoResolution]COMMA reJudge);
            Print(
                "\x25\x78\x2d\x49\x6e\x69\x74\x20\x76\x64\x65\x63\x2c\x20\x43\x50\x68\x61\x73\x65\x52\x65\x66\x2e\x2e\x2e" "\n"
                , slvAddr);
            pstIsr->stJobProc.defChromaPhase = 0;
            if((result = PR2000_SetTblBrief(i2cFd, slvAddr, cameraStandard, videoResolution, 1, &
                                            pstIsr->stJobProc)) < 0)
            {
                ErrorString(
                    "\x43\x61\x6e\x27\x74\x20\x73\x65\x74\x20\x74\x61\x62\x6c\x65\x20\x62\x72\x69\x65\x66" "\n"
                );
                return(result);
            }
            pstIsr->stJobProc.cntChromaLockTunn = 0;
            pstIsr->stJobProc.
            cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 50;
            pstIsr->stJobProc.cntJobTry = 0;
            result = pstIsr->
                     stJobProc.numJobStep;
            return(result);
        }
        else if(pstIsr->stJobProc.cntChromaLockTunn
                < MAX_CNT_TUNN_CHROMALOCK)
        {
            if((curStVidStatusReg.b.det_chroma) && (
                   curStVidStatusReg.b.lock_chroma))
            {
#ifdef SUPPORT_CEQ
                PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.stDetGainStatus);
                PR2000_GetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->
                                 stJobProc.stDetGainStatus, &stMeasureEqInfo);
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                PR2000_SetEQGain(i2cFd, slvAddr, &pstIsr
                                 ->stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &stMeasureEqInfo);
                memcpy(&pstIsr->stJobProc.stMeasureEqInfo, &stMeasureEqInfo, sizeof(
                           _stPR2000_MeasureEqInfo));
#endif
                pstIsr->stJobProc.C_LOCK_CNT = 1;
                Print(
                    "\x25\x78\x2d\x66\x69\x6e\x64\x20\x6c\x6f\x63\x6b\x20\x63\x68\x72\x6f\x6d\x61" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntChromaLockTunn = 0;
                pstIsr->stJobProc.
                cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 75;
                pstIsr->stJobProc.cntJobTry
                    = 0;
                result = pstIsr->stJobProc.numJobStep;
                return(result);
            }
            else if((
                        curStVidStatusReg.b.det_chroma) && (!curStVidStatusReg.b.lock_chroma))
            {
                tunnChromaPhase = (pstIsr->stJobProc.cntChromaLockTunn >> 1) + 1;
                tunnChromaPhase *= 40;
                if(pstIsr->stJobProc.cntChromaLockTunn & 1)
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase - tunnChromaPhase;
                }
                else
                {
                    tunnChromaPhase = pstIsr->stJobProc.defChromaPhase + tunnChromaPhase;
                }
                stReg.reg =
                    0x0146;
                u8RegData = ((tunnChromaPhase >> 16) & 0x1f) | 0x20;
                if((result = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) <
                   0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0147;
                u8RegData = (tunnChromaPhase >> 8) & 0xff;
                if((result
                    = PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                stReg.reg = 0x0148;
                u8RegData = (tunnChromaPhase) & 0xff;
                if((result =
                        PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                {
                    ErrorString(
                        "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                    ;
                    return(result);
                }
                Print(
                    "\x25\x78\x2d\x54\x75\x6e\x6e\x20\x43\x50\x68\x61\x73\x65\x3a\x30\x78\x25\x30\x38\x78" "\n"
                    , slvAddr COMMA tunnChromaPhase);
                {
                    stReg.reg = 0x0154;
                    u8RegData = 0x0e;
                    if((result =
                            PR2000_PageWrite(i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                    stReg.reg = 0x0154;
                    u8RegData = 0x0f;
                    if((result = PR2000_PageWrite(
                                     i2cFd, slvAddr, stReg.b.page, stReg.b.addr, u8RegData)) < 0)
                    {
                        ErrorString(
                            "\x69\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x67\x65\x20\x77\x72\x69\x74\x65" "\n")
                        ;
                        return(result);
                    }
                }
                pstIsr->stJobProc.cntChromaLockTunn++;
                pstIsr->stJobProc.
                cntWait300MsecTime = 1;
                pstIsr->stJobProc.numJobStep = 71;
                result = pstIsr->stJobProc.
                         numJobStep;
                return(result);
            }
        }
    }
    if((bitIrq == IRQ_TIMER1UP) && (pstIsr->stJobProc.
                                    numJobStep == 75))
    {
#ifdef SUPPORT_CEQ
        Dbg(
            "\x25\x78\x2d\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x37\x31\x29" "\n"
            , slvAddr);
        PR2000_GetDetGainStatus(i2cFd, slvAddr, &pstIsr->stJobProc.
                                stDetGainStatus);
        PR2000_GetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.
                         stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                         stMeasureEqInfo);
        Dbg(
            "\x25\x78\x2d\x64\x63\x47\x61\x69\x6e\x3a\x30\x78\x25\x30\x34\x78" "\n", pstIsr->
            stJobProc.stDetGainStatus.dcGain);
        if(pstIsr->stJobProc.stDetGainStatus.dcGain ==
           0xffff)
        {
            pstIsr->stJobProc.stTunnFactor.stepDir = -1;
            if(PR2000_GetTunnEQGain(i2cFd,
                                    slvAddr, &pstIsr->stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &
                                    pstIsr->stJobProc.stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3d\x20\x30\x78\x46\x46\x46\x46\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x73\x74\x65\x70\x2e" "\n"
                    , slvAddr);
                PR2000_SetEQGain(i2cFd, slvAddr, &pstIsr->stJobProc.stVidStatusReg, &
                                 pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.stMeasureEqInfo);
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 75;
                if(pstIsr->
                   stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc.
                    cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 76;
                    pstIsr->stJobProc.cntJobTry
                        = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 76;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else if(pstIsr->stJobProc.stDetGainStatus.dcGain < 0x1300)
        {
            pstIsr->stJobProc.
            stTunnFactor.stepDir = -1;
            if(PR2000_SetTunnVADCGain(i2cFd, slvAddr, &pstIsr->
                                      stJobProc.stVidStatusReg, &pstIsr->stJobProc.stDetGainStatus, &pstIsr->stJobProc.
                                      stTunnFactor, &pstIsr->stJobProc.stMeasureEqInfo) > 0)
            {
                Print(
                    "\x25\x78\x2d\x20\x20\x5b\x73\x79\x6e\x63\x4c\x65\x76\x65\x6c\x3a\x25\x30\x32\x78\x2c\x20\x64\x63\x3a\x25\x30\x34\x78\x2c\x20\x61\x63\x3a\x25\x30\x34\x78\x2c\x20\x63\x6f\x6d\x70\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x2c\x20\x61\x74\x74\x65\x6e\x5b\x25\x30\x34\x78\x2c\x20\x25\x30\x34\x78\x5d\x5d" "\n"
                    , slvAddr COMMA pstIsr->stJobProc.stDetGainStatus.syncLevel COMMA pstIsr->
                    stJobProc.stDetGainStatus.dcGain COMMA pstIsr->stJobProc.stDetGainStatus.acGain
                    COMMA pstIsr->stJobProc.stDetGainStatus.comp1 COMMA pstIsr->stJobProc.
                    stDetGainStatus.comp2 COMMA pstIsr->stJobProc.stDetGainStatus.atten1 COMMA
                    pstIsr->stJobProc.stDetGainStatus.atten2);
                Print(
                    "\x25\x78\x2d\x20\x20\x45\x71\x20\x66\x69\x6e\x65\x20\x74\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x64\x63\x5f\x67\x61\x69\x6e\x20\x3c\x20\x30\x78\x31\x33\x30\x30\x2c\x20\x64\x65\x63\x72\x65\x61\x73\x65\x20\x45\x71\x20\x76\x61\x64\x63\x67\x61\x69\x6e\x2e" "\n"
                    , slvAddr);
                pstIsr->stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 75
                                               ;
                if(pstIsr->stJobProc.cntJobTry++ > MAX_PR2000_CEQ_COMP_TBL_NUM)
                {
                    pstIsr->stJobProc
                    .cntWait300MsecTime = 0;
                    pstIsr->stJobProc.numJobStep = 76;
                    pstIsr->stJobProc.
                    cntJobTry = 0;

                }
                else
                {
                    result = pstIsr->stJobProc.numJobStep;
                    return(result);
                }
            }
            else
            {
                pstIsr->
                stJobProc.cntWait300MsecTime = 0;
                pstIsr->stJobProc.numJobStep = 76;
                pstIsr->stJobProc
                .cntJobTry = 0;

            }
        }
        else
        {
            Dbg(
                "\x25\x78\x2d\x45\x6e\x64\x20\x45\x51\x20\x46\x69\x6e\x65\x20\x54\x75\x6e\x6e\x69\x6e\x67\x2d\x31\x20\x66\x72\x6f\x6d\x20\x6e\x75\x6d\x4a\x6f\x62\x28\x37\x31\x29" "\n"
                , slvAddr);
            pstIsr->stJobProc.cntWait300MsecTime = 0;
            pstIsr->stJobProc.numJobStep = 76
                                           ;
            pstIsr->stJobProc.cntJobTry = 0;

        }
#else
        pstIsr->stJobProc.EQ_CNT = 2;
        pstIsr->stJobProc.cntWait300MsecTime = 0;
        pstIsr->
        stJobProc.numJobStep = 50;
        pstIsr->stJobProc.cntJobTry = 0;
        result = pstIsr->stJobProc.
                 numJobStep;
        return(result);
#endif
    }
   result = PR2000_ProcessCameraMonitor1(i2cFd, slvAddr, bitIrq, pArg);
    return(result);

}
